package com.cfpamf.ms.insur.pay.facade.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * Create By zhengjing on 2019-10-21 14:35
 */
@Getter
@Setter
public class PayFacadeConfiguration {

    @Autowired
    PayFacadeConfigProperties configProperties;

//    @Autowired
//    private ObjectFactory<HttpMessageConverters> messageConverters;

    @Bean
    public PaySignInterceptor interceptor() {
        return new PaySignInterceptor(configProperties.getSourceSys(), configProperties.getKey(), build());
    }

    private ObjectMapper build() {
        return Jackson2ObjectMapperBuilder
                .json()
                .simpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .failOnUnknownProperties(false).build();
    }

    @Bean
    public JacksonSignEncoder jacksonSignEncoder() {
        return new JacksonSignEncoder(build());
    }

    @Bean
    public PayValidDecoder payValidDecoder() {
        return new PayValidDecoder(
//                new ResponseEntityDecoder(new SpringDecoder(this.messageConverters)),
                configProperties.getKey(), build());
    }
}
